package hk.m4s.lr.repair.test.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.SelectCouponModel;

/**
 * Created by qi.wang on 2017/3/16.
 */

public class UseCardAdapter extends BaseAdapter {
    public List<SelectCouponModel> list = new ArrayList<>();
    Context context;
    LayoutInflater inflater;
    public UseCardAdapter(Context context, List<SelectCouponModel> data) {
        this.context = context;
        this.list = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.list_item_use_card, parent, false);
            holder.couponName = (TextView) convertView.findViewById(R.id.couponName);
            holder.couponTime = (TextView) convertView.findViewById(R.id.couponTime);
            holder.couponPrice = (TextView) convertView.findViewById(R.id.couponPrice);
            holder.couponRule = (TextView) convertView.findViewById(R.id.couponRule);


            holder.timeTips= (TextView) convertView.findViewById(R.id.timeTips);
            holder.couponState= (TextView) convertView.findViewById(R.id.couponUseState);
            holder.couponUsedState= (TextView) convertView.findViewById(R.id.couponUsedState);
            holder.couponUp=(ImageView)  convertView.findViewById(R.id.couponUp);
            holder.couponBg = (LinearLayout) convertView.findViewById(R.id.couponBg);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        SelectCouponModel newsModel = list.get(position);
        holder.couponName.setText(newsModel.getCouponName());
        holder.couponTime.setText(newsModel.getStartTime());
        holder.couponRule.setText(newsModel.getCouponTips());
        holder.couponPrice.setText(newsModel.getCouponPrice());
        if(newsModel.getState().equals("0")){
            holder.couponState.setVisibility(View.VISIBLE);
            holder.couponUsedState.setVisibility(View.GONE);
            holder.couponBg.setBackgroundResource(R.mipmap.cardbg);
            holder.timeTips.setText("购买时间:");
        }else if(newsModel.getState().equals("1")){
            holder.couponState.setVisibility(View.GONE);
            holder.couponUsedState.setVisibility(View.VISIBLE);
            holder.timeTips.setText("已用时间:");
            holder.couponBg.setBackgroundResource(R.mipmap.selectnobg);
        }




        return convertView;
    }

    public static class ViewHolder {
        TextView couponName, couponTime, couponPrice, couponRule,timeTips,couponState,lookTipsTx,couponUsedState;
        ImageView couponUp;

        private LinearLayout couponBg;
    }




}
